package com.itentbase.match.common.utils;


import com.itentbase.match.exception.RRException;
import com.itentbase.match.pojo.enums.ResponseEnum;
import lombok.Data;

/**
 * @author mek
 * @date 2023/4/15
 */
@Data
public class Rs {

    /**
     * 错误
     *
     * @param msg 消息
     * @return {@link  R}
     */
    public static R error(String msg){
        return new  R().setSuccess(false).setMsg(msg);
    }
    public static  R error(){
        return new  R().setSuccess(false);
    }
    public static  R error(int code, String msg){
        return new  R().setMsg(msg).setCode(code);
    }
    public static  R error(ResponseEnum responseEnum){
        return new  R().setMsg(responseEnum.getMessage()).setCode(responseEnum.getCode());
    }
    //public static <T>  R<T> error(T data){
    //    return new  R<T>().setSuccess(false).setData(data);
    //}

    /**
     * 成功
     *
     * @param msg 消息
     * @return {@link  R}
     */
    public static  R success(String msg){
        return new  R().setSuccess(true).setMsg(msg);
    }
    public static  R success(){
        return new  R().setSuccess(true);
    }
    public static  R successData(String data){
        return new  R().setSuccess(true).setData(data);
    }
    public static <T>  R<T> success(T data){
        return new  R<T>(data);
    }
    public static  R success(int code, String message){
        return new  R().setCode(code).setMsg(message);
    }

    /**
     * 抛出异常
     *
     * @param msg 消息
     * @return {@link T}
     */
    public static <T> T raise(String msg){
        throw new RRException(msg);
    }

    public static <T> T raise(ResponseEnum responseEnum){
        throw new RRException(responseEnum.getMessage());
    }

}
